<?php


namespace app\store\controller\market;

use app\store\model\Coupon as CouponModel;
use app\store\controller\Controller;
use app\store\model\Lottery as LotteryModel;
class Lottery extends Controller
{
    /* @var LotteryModel $model */
    private $model;

    /**
     * 构造方法
     * @throws \app\common\exception\BaseException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new LotteryModel;
    }
    public function index(){

        $list = $this->model->getList();
        return $this->fetch('index', compact('list'));
    }
    public function add(){
        if (!$this->request->isAjax()) {
            $CouponModel = new CouponModel();
            $couponLists = $CouponModel->getLotteryCouponList();
            return $this->fetch('add',compact('couponLists'));
        }
        $lottery = $this->postData('lottery');
        $lotteryJiangpin = $this->postData('lottery_jiangpin');
        // 新增记录
        if ($this->model->addLottery($lottery,$lotteryJiangpin)) {
            return $this->renderSuccess('添加成功', url('market.lottery/index'));
        }
        return $this->renderError($this->model->getError() ?: '添加失败');
    }
}